package DbConnect;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DbConnect {

	private static String driverName = "com.mysql.jdbc.Driver";   //����������
	private static String userName = "root";                      //���ݿ��û���
	private static String userPwd = "gaojintian";                     //����
	private static String dbName = "gaoyangluntan3";                    //���ݿ���
	  
	public static Connection getDBconnection(){
		String  url1="jdbc:mysql://localhost/"+dbName;
		String  url2 ="?user="+userName+"&password="+userPwd;
		String  url3="&useUnicode=true&characterEncoding=GB2312";
		String  url =url1+url2+url3;
		try{
		    Class.forName(driverName);		
		    Connection con=DriverManager.getConnection(url); 
		    return con;		   
	    }catch (Exception e) {			
			   e.printStackTrace();
		}
		return null;
    } 
	   
    public static void closeDB(Connection con,Statement  stmt, ResultSet rs){
 	   try{
 		   if(rs!=null) rs.close(); 
 		   if(stmt!=null) stmt.close();
		   if(con!=null) con.close();				 
	   }catch (SQLException e) {				
			e.printStackTrace();			
	   }
	}
    public static void closeDB1(Connection con,Statement  stmt, ResultSet rs){
  	   try{
  		   if(rs!=null) rs.close(); 
  		   if(stmt!=null) stmt.close();
 		   if(con!=null) con.close();				 
 	   }catch (SQLException e) {				
 			e.printStackTrace();			
 	   }
 	}
}
